package com.example.controller;

import com.example.domain.dto.PaperDTO;
import com.example.domain.po.Paper;
import com.example.service.PaperService;
import com.example.util.PageBean;
import com.example.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/paper")
public class PaperController {
    @Autowired
    private PaperService paperService;

    @GetMapping("/listByPage")
    public Result<PageBean<Paper>> listByPage(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) String name //卷名
    ){
        return Result.success(paperService.listByPage(pageNum,pageSize,name));
    }

    /**
     * 新增试卷
     * @param paperDTO
     * @return
     */
    @PostMapping("/add")
    public Result<String> add(@RequestBody PaperDTO paperDTO){
        paperService.add(paperDTO);
        return Result.success("新增试卷成功");
    }

    /**
     * 修改考卷
     * @param paperDTO
     * @return
     */
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody PaperDTO paperDTO){
        paperService.edit(paperDTO);
        return Result.success("修改试卷成功");
    }

    /**
     * 通过id获取考卷信息
     * @return
     */
    @GetMapping("/getById")
    public Result<PaperDTO> getById(Integer id){
        return Result.success(paperService.getById(id));
    }

    /**
     * 通过id删除考卷
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById")
    public Result<String> deleteById(Integer id){
        paperService.deleteById(id);
        return Result.success("删除成功");
    }
}
